package br.com.webthor.service.impl;

import java.util.Map;

import br.com.webthor.service.BaseService;
import br.com.webthor.service.CepFacilService;

import com.sun.jersey.api.client.UniformInterfaceException;

public class CepFacilServiceImpl extends BaseService implements CepFacilService {

	private static final String CEP_FACIL_TOKEN = "0EFA168D-ABD5-4EED-A381-763868E0E930";
	
	private static final String URL_CEP_FACIL = "http://www.cepfacil.com.br/service/?filiacao=";
	
	private static final String COMP_CEP = "&cep=";
	
	private static final String FORMATO_REQUISICAO_JSON = "&formato=json";
	
	private String urlConsulta = null;
	
	
	//Constantes de retorno
	public static final String LABEL_CEP = "CEP";
	public static final String LABEL_LOGRADOURO = "Logradouro";
	public static final String LABEL_LOGRADOURO_TIPO = "LogradouroTipo";
	public static final String LABEL_CIDADE = "Cidade";
	public static final String LABEL_UF = "UF";
	public static final String LABEL_BAIRRO = "Bairro";
	
	@Override
	public Map<String,String> consultarEnderecoCep(String cep) throws UniformInterfaceException{
		urlConsulta = URL_CEP_FACIL+CEP_FACIL_TOKEN+COMP_CEP+cep+FORMATO_REQUISICAO_JSON;
		iniciarRecurso(urlConsulta);
		String resposta = webResource.accept(javax.ws.rs.core.MediaType.TEXT_PLAIN).get(String.class);
		Map<String,String> mapRetorno = popularMapResultado(resposta);
		return mapRetorno; 
	}
}
